#include <iostream>  
#include <vector>  
#include <climits>  
using namespace std;  
  
void floydWarshall(vector<vector<int>>& graph) {  
    int V = graph.size();  
  
    // 初始化距离矩阵为输入图的邻接矩阵  
    vector<vector<int>> dist(V, vector<int>(V));  
    for (int i = 0; i < V; i++) {  
        for (int j = 0; j < V; j++) {  
            dist[i][j] = graph[i][j];  
        }  
    }  
  
    // 对于每个顶点，考虑所有的对（i，j）的顶点对，看看是否可以通过 k 获得更短的距离  
    for (int k = 0; k < V; k++) {  
        for (int i = 0; i < V; i++) {  
            for (int j = 0; j < V; j++) {  
                if (dist[i][k] + dist[k][j] < dist[i][j]) {  
                    dist[i][j] = dist[i][k] + dist[k][j];  
                }  
            }  
        }  
    }  
  
    // 打印结果  
    for (int i = 0; i < V; i++) {  
        for (int j = 0; j < V; j++) {  
            if (dist[i][j] == INT_MAX) {  
                cout << "INF ";  
            } else {  
                cout << dist[i][j] << " ";  
            }  
        }  
        cout << endl;  
    }  
}  
  
int main() {  
    // 创建带权有向图的邻接矩阵表示形式  
    vector<vector<int>> graph = {  
        {0, 5, INT_MAX, 10},  
        {INF, 0, 3, INF},  
        {INF, INF, 0, 1},  
        {INF, INF, INF, 0}  
    };  
  
    // 运行弗洛伊德算法并打印结果  
    floydWarshall(graph);  
  
    return 0;  
}